<?php
class BulletinAction extends LoginAction
{
	public function index ()
	{
		$BulletinModel = M('Bulletin');
		$size = $BulletinModel->count();
		$Page = $this->getPage($size);
		$bs = $BulletinModel->field('id,title,uid,create_time')->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('bs', $bs);
		$this->assign('page', $Page->show());
		$this->display();
	}

	/**
	 * 添加公告
	 * @author Ice <iceinto@mallog.com.cn>
	 */
	public function add ()
	{
		if(isPost()){
			$userInfo = getLoginUserInfo();
			$data = array();
			$data['title'] = trim(getPost('title'));
			$data['content'] = trim(getPost('content'));
			$data['create_time'] = $data['update_time'] = time();
			$data['uid'] = $userInfo['id'];
			if(M('Bulletin')->add($data)){
				$this->successMessage("添加成功！");
			}else{
				$this->error("添加失败！");
			}
		}
		$this->display();
	}
	/**
	* 更新公告
	* @author Ice <iceinto@mallog.com.cn>
	*/
	public function edit ()
	{
		$id = intval(getGet('id'));
		$Bulletin = M('Bulletin');
		$b = $Bulletin->find($id);
		if(isPost()){
			$userInfo = getLoginUserInfo();
			$data = array();
			$data['id'] = $id;
			$data['title'] = trim(getPost('title'));
			$data['content'] = trim(getPost('content'));
			$data['update_time'] = time();
			$data['uid'] = $userInfo['id'];
			if($Bulletin->save($data)){
				$b = $Bulletin->find($id);
				$this->successMessage("修改成功！");
			}else{
				$this->error("修改失败！");
			}
		}
		$this->assign('b', $b);
		$this->display();
	}
}
?>